package com.mexcad.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mexcad.db.delegate.DelegateConnectors;
import com.mexcad.db.dto.Credito;
import com.mexcad.db.dto.Usuario;
import com.mexcad.utils.Formatter;

public class ConsultaCredito extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

   

public ConsultaCredito() {
	super();
}   	


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	executeServlet(request,response);
}


protected void executeServlet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	HttpSession sessionHTTP = request.getSession();
	PrintWriter out;
	String credito =request.getParameter("credito");
	String rfc =request.getParameter("rfc");
	///String query= "";
	int idCred = 0;

	try{
		idCred = Integer.parseInt(credito);

	}catch(Exception e){}
	
	Credito cred = DelegateConnectors.consultaCreditoNumEmpleadoRFC(idCred, rfc);
	
	response.setContentType("text/html");
	request.setCharacterEncoding("UTF-8");
	
	out = response.getWriter();
	
	//cadena  = "{total:10, data: [ {anio: '10', id:'mica', partida:46.5, descripcion: 'hola'}]}";
	if( cred  != null){
		
	
		
		sessionHTTP.setMaxInactiveInterval(1800); // 30 minutos = 60 segundos x 30 = 1800
		out.print(response.encodeUrl("jsp/reporteCliente.jsp?credito="+cred.getCkCredito().getIdCredito())+"&rfc="+cred.getRfc());
		

	}else{
		out.print(response.encodeUrl("index.html"));
	}
	out.close(); 
}  	

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		executeServlet(request,response);

	}
}
